#include <algorithm>
#include <iostream>
#include <ranges>
#include <random>
#include <vector>
#include "log.h"
#include "sorting_algorithm.h"

namespace {
constexpr size_t MINIMUN_ARRAY_LENGTH = 100;
constexpr size_t MAXIMUN_ARRAY_LENGTH = 10000;
constexpr int32_t MINIMUN_RANDOM_NUMBER = -1000;
constexpr int32_t MAXIMUN_RANDOM_NUMBER = 1000;

std::vector<int32_t> GenerateRandomArray()
{
    std::random_device rd;
    std::mt19937 gen(rd());

    std::uniform_int_distribution<size_t> count_dist(MINIMUN_ARRAY_LENGTH, MAXIMUN_ARRAY_LENGTH);
    size_t num_elements = count_dist(gen);
    
    // 随机数值范围
    std::uniform_int_distribution<int32_t> value_dist(MINIMUN_RANDOM_NUMBER, MAXIMUN_RANDOM_NUMBER);
    
    // 使用 generate_n 生成随机数
    std::vector<int32_t> random_numbers;
    random_numbers.reserve(num_elements);
    
    std::generate_n(std::back_inserter(random_numbers), 
                    num_elements, 
                    [&]() { return value_dist(gen); });
    
    SYS_LOG(_INFO) << "使用 generate_n 生成了 " << random_numbers.size() << " 个随机数\n";
    return random_numbers;
}
} // namespace

int main() {
    std::vector<int32_t> data = GenerateRandomArray();

    BubbleSort bs;
    auto bsResult = bs.Executor(data);

    InsertionSort is;
    auto isResult = is.Executor(data);
    if (bsResult != isResult) {
        SYS_LOG(_ERROR) << "bsResult != isResult" << '\n';
    }

    QuickSort qs;
    auto qsResult = qs.Executor(data);
    if (isResult != qsResult) {
        SYS_LOG(_ERROR) << "isResult != qsResult" << '\n';
    }

    MergeSort ms;
    auto msResult = ms.Executor(data);
    if (qsResult != msResult) {
        SYS_LOG(_ERROR) << "qsResult != msResult" << '\n';
    }

    HeapifySort hs;
    auto hsResult = hs.Executor(data);
    if (msResult != hsResult) {
        SYS_LOG(_ERROR) << "msResult != hsResult" << '\n';
    }

    return 0;
}